/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package quanlykho;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Admin
 */
public class ThongTinHangHoa extends javax.swing.JPanel {

    /**
     * Creates new form ThongTinHangHoa
     */
    DefaultTableModel model;
    static String tenloaihang;
    static String tenhang;
    static String mahang;
    static int choose;
    static String maloaihang;
    static int luachon=0;
    public ThongTinHangHoa(String str) {
        try {
            initComponents();
            loadCb(cb1,"nhacungcap", 1);
            tenloaihang=str;
            t1.setEnabled(false);
            t1.setText(str);
            an();

            System.out.println(str);
            //System.out.println("alo");
            model = (DefaultTableModel) jt1.getModel();
            int num=jt1.getRowCount();
            for (int i = num-1; i >= 0; i--) {
                model.removeRow(i);
            }
            Ketnoi a = new Ketnoi();
            Connection con = a.connect();
            PreparedStatement pst1 = con.prepareCall("Select * from loaihang where tenloaihh = ?");
            pst1.setString(1, str);
            ResultSet rs1= pst1.executeQuery();
            String str1= null;
            while(rs1.next())
            {
                str1=rs1.getString(1);
            }
            maloaihang=str1;
            System.out.println(str1);
            PreparedStatement pst = con.prepareCall("Select * from hanghoa where maloaihh = ?");
            pst.setString(1, str1);
            ResultSet rs = pst.executeQuery();
            Vector b = null;
            while(rs.next())
            {
                b=new Vector();
                b.add(rs.getString(1));
                b.add(rs.getString(2));
                b.add(rs.getString(5));
                b.add(rs.getString(7));
                b.add(rs.getString(8));
                model.addRow(b);
            }
        } catch (SQLException ex) {
            Logger.getLogger(ThongTinHangHoa.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public void loadTable(String str)
    {
        try {
            model = (DefaultTableModel) jt1.getModel();
                int num=jt1.getRowCount();
                for (int i = num-1; i >= 0; i--) {
                    model.removeRow(i);
                }
                Ketnoi a = new Ketnoi();
                Connection con = a.connect();
                PreparedStatement pst1 = con.prepareCall("Select * from loaihang where tenloaihh = ?");
                pst1.setString(1, str);
                ResultSet rs1= pst1.executeQuery();
                String str1= null;
                while(rs1.next())
                {
                    str1=rs1.getString(1);
                }
                System.out.println(str1);
                PreparedStatement pst = con.prepareCall("Select * from hanghoa where maloaihh = ?");
                pst.setString(1, str1);
                ResultSet rs = pst.executeQuery();
                Vector b = null;
                while(rs.next())
                {
                    b=new Vector();
                    b.add(rs.getString(1));
                    b.add(rs.getString(2));
                    b.add(rs.getString(5));
                    b.add(rs.getString(7));
                    b.add(rs.getString(8));
                    model.addRow(b);
                }
        } catch (SQLException ex) {
            Logger.getLogger(ThongTinHangHoa.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public void an()
    {
            t2.setVisible(false);
            t3.setVisible(false);
            t5.setVisible(false);
            t6.setVisible(false);
            t4.setVisible(false);
            l1.setText("");
            l2.setText("");
            l3.setText("");
            l4.setText("");
            l5.setText("");
            l6.setText("");
            b4.setVisible(false);
            b5.setVisible(false);
            cb1.setVisible(false);
            t2.setText("");
            t3.setText("");
            t4.setText("");
            t5.setText("");
            t6.setText("");
    }
    public void xoa()
    {
            t2.setText("");
            t3.setText("");
            t4.setText("");
            t5.setText("");
            t6.setText("");
    };
    public void hien()
    {
            t2.setVisible(true);
            t3.setVisible(true);
            t5.setVisible(true);
            t6.setVisible(true);
            t4.setVisible(true);
            l1.setText("Mã hàng");
            l2.setText("Tên hàng");
            l3.setText("Thông tin");
            l4.setText("Giá nhập");
            l5.setText("Giá xuất");
            l6.setText("Nhà CC");
            b4.setVisible(true);
            b5.setVisible(true);
            cb1.setVisible(true);
    }
    public boolean kiemtra(String s)
    {
        boolean flag  = true;
        try {
            Ketnoi a = new Ketnoi();
            Connection con = a.connect();
            
            PreparedStatement pst = con.prepareCall("Select * from hanghoa");
            ResultSet rs = pst.executeQuery();
            ArrayList mang = new ArrayList();
            while(rs.next())
            {
                mang.add(rs.getString(1));
            }
            for (int i = 0; i < mang.size(); i++) {
                if(tenhang.toUpperCase().equals(mang.get(i).toString()))
                {
                    flag=false;
                }
            }
            
        } catch (SQLException ex) {
            Logger.getLogger(ThongTinHangHoa.class.getName()).log(Level.SEVERE, null, ex);
        }
        return flag;
    }
    public void loadCb(JComboBox cb,String str,int index)
    {
        try {
            Ketnoi a = new Ketnoi();
            Connection con = a.connect();
            cb.removeAllItems();
            cb.addItem("Lựa chọn");
            String str1="Select * from "+str;
            System.out.println(str1);
            PreparedStatement pst = con.prepareCall(str1);
            ResultSet rs = pst.executeQuery();
            while(rs.next())
            {
                cb.addItem(rs.getString(index));  
            }
            
        } catch (SQLException ex) {
            Logger.getLogger(ThongTinHangHoa.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public Vector getCb(String str,int index)
    {
        Vector v = new Vector();
        try {
            Ketnoi a = new Ketnoi();
            Connection con = a.connect();
            String str1="Select * from "+str;
            PreparedStatement pst = con.prepareCall(str1);
           ResultSet rs = pst.executeQuery();
            while(rs.next())
            {
                v.add(rs.getString(index));  
            }
            String st = null;
        } catch (SQLException ex) {
            Logger.getLogger(ThongTinHangHoa.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jt1 = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        b1 = new javax.swing.JButton();
        b2 = new javax.swing.JButton();
        b3 = new javax.swing.JButton();
        t1 = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        l1 = new javax.swing.JLabel();
        l2 = new javax.swing.JLabel();
        l3 = new javax.swing.JLabel();
        t2 = new javax.swing.JTextField();
        t3 = new javax.swing.JTextField();
        t5 = new javax.swing.JTextField();
        t6 = new javax.swing.JTextField();
        l4 = new javax.swing.JLabel();
        l5 = new javax.swing.JLabel();
        t4 = new javax.swing.JTextField();
        l6 = new javax.swing.JLabel();
        b4 = new javax.swing.JButton();
        b5 = new javax.swing.JButton();
        cb1 = new javax.swing.JComboBox();

        setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        setForeground(new java.awt.Color(102, 255, 204));

        jt1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Mã Mặt Hàng", "Tên Hàng", "Số lượng còn", "Giá Nhập", "Giá Xuất"
            }
        ));
        jScrollPane1.setViewportView(jt1);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel1.setForeground(new java.awt.Color(51, 0, 255));
        jLabel1.setText("Thông Tin Các Mặt Hàng");
        jLabel1.setToolTipText("");

        b1.setText("Thêm");
        b1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b1ActionPerformed(evt);
            }
        });

        b2.setText("Xóa");

        b3.setText("Sửa");
        b3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b3ActionPerformed(evt);
            }
        });

        t1.setFont(new java.awt.Font("Tahoma", 0, 18));
        t1.setForeground(new java.awt.Color(255, 51, 51));
        t1.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        t1.setBorder(null);
        t1.setCaretColor(new java.awt.Color(255, 0, 51));
        t1.setDisabledTextColor(new java.awt.Color(255, 0, 0));

        l1.setText("Mã hàng");

        l2.setText("Tên hàng");

        l3.setText("Thông tin hàng");

        t2.setDisabledTextColor(new java.awt.Color(255, 255, 255));
        t2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                t2ActionPerformed(evt);
            }
        });

        t5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                t5ActionPerformed(evt);
            }
        });

        l4.setText("Giá Nhập");

        l5.setText("Giá Xuất");

        l6.setText("Nhà CC");

        b4.setText("Lưu");
        b4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b4ActionPerformed(evt);
            }
        });

        b5.setText("Nhập lại");
        b5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(l1, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(l3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(l2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(b4, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(b5))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(t3, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(t4, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(t2, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(l5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(l4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(l6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(t5)
                    .addComponent(t6)
                    .addComponent(cb1, 0, 92, Short.MAX_VALUE))
                .addContainerGap(34, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(l1)
                    .addComponent(t2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(t5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(l4))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(l2)
                    .addComponent(t3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(t6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(l5))
                .addGap(25, 25, 25)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(l3)
                    .addComponent(t4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(l6)
                    .addComponent(cb1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(b4)
                    .addComponent(b5))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(43, 43, 43)
                        .addComponent(b1, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(69, 69, 69)
                        .addComponent(b2, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(63, 63, 63)
                        .addComponent(b3, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(134, 134, 134)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(t1, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 463, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(t1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(b2)
                    .addComponent(b3)
                    .addComponent(b1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void b1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b1ActionPerformed
            // TODO add your handling code here:
        luachon=0;
        loadCb(cb1,"nhacungcap", 1);
        hien();
        xoa();
    }//GEN-LAST:event_b1ActionPerformed

    private void b3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b3ActionPerformed
            // TODO add your handling code here:
        luachon=1;
        loadCb(cb1,"nhacungcap", 1);

        String s2=null;
        String s3=null;
        String s4=null;
        String s5=null;
        int a1=0;
        int a2=0;
        int a3 =0;
        Ketnoi a = new Ketnoi();
        Connection con = a.connect();
        if(jt1.getSelectedRow()<0)
        {
            JOptionPane.showMessageDialog(this,"Vui lòng lựa chọn sản phẩm cần sửa ở trên.");
        }
        if(jt1.getSelectedRow()>=0)
        {
            try {
                String s1=jt1.getValueAt(jt1.getSelectedRow(),0).toString();
                hien();
                PreparedStatement pt = con.prepareCall("Select * from hanghoa where mahh = ?");
                pt.setString(1, s1);
                ResultSet rs = pt.executeQuery();
                while(rs.next())
                {
                   s2=rs.getString(2);
                   s3=rs.getString(4);
                   s4=rs.getString(7);
                   s5=rs.getString(8);
                }
                t2.setText(s1);
                t3.setText(s2);
                t4.setText(s3);
                t5.setText(s4);
                t6.setText(s5);
                System.out.println(s1);
                mahang=s1;
            } catch (SQLException ex) {
                Logger.getLogger(ThongTinHangHoa.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

    }//GEN-LAST:event_b3ActionPerformed

    private void b4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b4ActionPerformed

            // TODO add your handling code here:
            
            Vector v = getCb("nhacungcap", 1);
            tenhang=t2.getText();
            Ketnoi a = new Ketnoi();
            Connection con = a.connect();
            boolean flag=true;
            flag=kiemtra(tenhang);
            int test=1;
            int k = cb1.getSelectedIndex();
            
            if(k<1)
            {
                test=8;

            }
            if(t6.getText().length()==0)
            {
                test=7;
            }
            if(t5.getText().length()==0)
            {
                test=6;
            }
            if(t4.getText().length()==0)
            {
                test=5;
            }
             if(t3.getText().length()==0)
            {
                test=4;
            }
            if(t2.getText().length()==0)
            {
                test=3;
            }
            if(flag == false)
            {
                test=2;
            }
            if(test==2&&luachon==0)
            {
                JOptionPane.showMessageDialog(this, "Mã sản phẩm đã tồn tại");
                t2.requestFocus();
                test=2;
            }
             if(test==3)
            {
                JOptionPane.showMessageDialog(this, "Không được để trống Mã sản phẩm");
                t2.requestFocus();
                test=2;
            }
            if(test==4)
            {
                JOptionPane.showMessageDialog(this, "Không được để trống Tên sản phẩm");
                t3.requestFocus();
                test=2;
            }
            if(test==5)
            {
                JOptionPane.showMessageDialog(this, "Không được để trống Thông tin sản phẩm");
                t4.requestFocus();
                test=2;
            }
            if(test==6)
            {
                JOptionPane.showMessageDialog(this, "Không được để trống giá nhập");
                t5.requestFocus();
                test=2;
            }
            if(test==7)
            {
                JOptionPane.showMessageDialog(this, "Không được để trống giá xuất");
                t6.requestFocus();
                test=2;
            }
            if(test==8)
            {
                JOptionPane.showMessageDialog(this, "Lựa chọn Nhà cung cấp");
                t6.requestFocus();
                test=2;
            }

            if(test==1)
            {
            try {
                String s1=null;
                String s2=null;
                String s3=null;
                String s4=null;
                String s5=null;
                int a1=0;
                int a2=Integer.parseInt(t5.getText());
                int a3=Integer.parseInt(t6.getText());
                s1=t2.getText().toUpperCase();
                s2=t3.getText();
                s3=maloaihang;
                s4=t4.getText();
                s5=v.get(k-1).toString();
                String s6=v.get(k-1).toString();
                //System.out.println(s6);
                PreparedStatement pst=null;
                if(luachon==0)
                {
                pst = con.prepareCall("Insert into HangHoa values(?,?,?,?,?,?,?,?)");
                pst.setString(1, s1);
                pst.setString(2, s2);
                pst.setString(3, s3);
                pst.setString(4, s4);
                pst.setInt(5, a1);
                pst.setString(6, s6);
                pst.setInt(7, a2);
                pst.setInt(8, a3);
                pst.executeUpdate();
                }
                if(luachon==1)
                {
                pst = con.prepareCall("Update HangHoa set mahh = ?,tenhh=?,tthh=?,mancc=?,gianhap=?,giaxuat=?");
                pst.setString(1, s1);
                pst.setString(2, s2);
                pst.setString(3, s4);
                pst.setString(4, s6);
                pst.setInt(5, a2);
                pst.setInt(6, a3);
                pst.executeUpdate();   
                }

                loadTable(tenloaihang);
                an();
            } catch (SQLException ex) {
                Logger.getLogger(ThongTinHangHoa.class.getName()).log(Level.SEVERE, null, ex);
            }
            }
            System.out.println(test);
    }//GEN-LAST:event_b4ActionPerformed

    private void b5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b5ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_b5ActionPerformed

    private void t2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_t2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_t2ActionPerformed

    private void t5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_t5ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_t5ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton b1;
    private javax.swing.JButton b2;
    private javax.swing.JButton b3;
    private javax.swing.JButton b4;
    private javax.swing.JButton b5;
    private javax.swing.JComboBox cb1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jt1;
    private javax.swing.JLabel l1;
    private javax.swing.JLabel l2;
    private javax.swing.JLabel l3;
    private javax.swing.JLabel l4;
    private javax.swing.JLabel l5;
    private javax.swing.JLabel l6;
    private javax.swing.JTextField t1;
    private javax.swing.JTextField t2;
    private javax.swing.JTextField t3;
    private javax.swing.JTextField t4;
    private javax.swing.JTextField t5;
    private javax.swing.JTextField t6;
    // End of variables declaration//GEN-END:variables
}
